package com.company.笔试.包含min函数的栈;

import java.util.Stack;

public class Solution {
    
    Stack<Integer> stack = new Stack<>();
    Stack<Integer> stackHelp = new Stack<>(); //来个同步辅助栈
    
    public void push(int node) {
        stack.push(node);//主栈进入
        //判断辅助栈是否为空
        if(stackHelp.isEmpty()){
            stackHelp.push(node);    
        }else{
            //主栈的元素对应的最小值保存到辅助栈
            //  -1   2   1
            //  -1  -1  -1    
            //简单来说就是用辅助栈保存主栈对应的最小值   主栈弹出元素,辅助栈也弹出该元素对应的最小值
            stackHelp.push(Math.min(stackHelp.peek(),node));
        }
    }
    
    public void pop() {
        stackHelp.pop();
        stack.pop();
    }
    
    public int top() {
        return stack.peek();
    }
    
    public int min() {
        return stackHelp.peek();
    }
}